import Parse from 'parse'
import { Form, Button, Input } from 'antd'

const LoginPage = ({ login, setPage }) => {
  const onFinish = async (values) => {
    const { username, password } = values
    try {
      const user = await Parse.User.logIn(username, password, { usePost: true })
      console.log(user, '登录成功')
      login(true)
    } catch (err) {
      console.log(err, '登录失败')
    }
  }
  return <div>
    <Form
      name="basic"
      labelCol={{
        span: 8
      }}
      wrapperCol={{
        span: 16
      }}
      initialValues={{
        remember: true
      }}
      onFinish={onFinish}
      autoComplete="off"
    >
      <Form.Item
        label="账号"
        name="username"
        rules={[
          {
            required: true,
            message: '请输入用户名'
          }
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="密码"
        name="password"
        rules={[
          {
            required: true,
            message: '请输入密码'
          }
        ]}
      >
        <Input.Password />
      </Form.Item>
      <Form.Item
        wrapperCol={{
          offset: 4,
          span: 20
        }}
      >
        <Button htmlType="submit" type="primary" style={{ marginRight: '20px' }}>
          登录
        </Button>
        <Button onClick={() => setPage(2)}>
          注册
        </Button>
      </Form.Item>
    </Form>
  </div>
}

export default LoginPage
